package cn.hycat.leetcode.middle;

/**
 * @author 吕泽浩业
 * @version 1.0
 */
public class L3无重复最长子串 {
    public int lengthOfLongestSubstring(String s) {
        if(s == null || s.length() == 0) return 0;
        int[] map = new int[256];
        for(int i = 0; i < 256; i++)  {
            map[i] = -1;
        }
        char[] chars = s.toCharArray();
        int cur = 1;
        int ans = 1;
        map[chars[0]] = 0;
        for(int i = 1; i < chars.length; i++) {
            cur = Math.min(i - map[chars[i]], cur + 1);
            ans = Math.max(cur, ans);
            map[chars[i]] = i;
        }
        return ans;
    }
}
